package com.application.Adapter;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.application.Activity.R;
import com.application.Adapter.MyResultDoTestAdapter.ViewOption;

public class MyResultDoTestAdapter extends ArrayAdapter<ViewOption> {
	Context mcontent;
	private int mResources;
	private ArrayList<ViewOption> mOptionsList;

	public MyResultDoTestAdapter(Context context, int resource,
			ArrayList<ViewOption> optionList) {
		super(context, resource, optionList);
		mcontent = context;
		mOptionsList = optionList;
		mResources = resource;
	}

	@Override
	public int getCount() {
		return mOptionsList.size();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position,
			View convertView, ViewGroup parent) {
		ViewOption viewOption = mOptionsList.get(position);
		Log.d("PEERDROID","position: " + position);
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater lInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = lInflater.inflate(R.layout.row_resultdotest, null, true);
		}
		if (viewOption != null) {
			Log.d("PEERDROID","text: " + viewOption.get_contentOption().toString());
			TextView txtcontent = (TextView) rowView.findViewById(R.id.rowresult_content);
			txtcontent.setText(viewOption.get_contentOption().toString());
			
			ImageView imgresult = (ImageView) rowView.findViewById(R.id.rowresult_imgresult);
			if (viewOption.get_typeOption() == 1)// single choice
			{
				switch (viewOption.get_result()) {
				case 1: // tra loi la sai
				{
					imgresult.setImageResource(R.drawable.radio_check_false);
					imgresult.setVisibility(View.VISIBLE);
					break;
				}
				case 2:// tra loi dung
				{
					imgresult.setImageResource(R.drawable.radio_check_true);
					imgresult.setVisibility(View.VISIBLE);
					break;
				}
				case 3: // cau tra loi dung
				{
					imgresult.setImageResource(R.drawable.radio_uncheck_true);
					imgresult.setVisibility(View.VISIBLE);
					Log.d("PEERDROID","ha dien ");
					break;
				}
				default:
				{
					imgresult.setVisibility(View.INVISIBLE);
					break;
				}
				}
			}
			if (viewOption.get_typeOption() == 2) {
				switch (viewOption.get_result()) {
				case 1:// tra loi sai
				{
					imgresult.setImageResource(R.drawable.checkbox_check_false);
					imgresult.setVisibility(View.VISIBLE);
					break;
				}
				case 2:// tra loi dung
				{
					imgresult.setImageResource(R.drawable.checkbox_check_true);
					imgresult.setVisibility(View.VISIBLE);
					break;
				}
				case 3:// dap an dung
				{
					imgresult.setImageResource(R.drawable.checkbox_uncheck_true);
					imgresult.setVisibility(View.VISIBLE);
					break;
				}
				default:
				{
					imgresult.setVisibility(View.INVISIBLE);
					break;
				}
				}
			}
		}

		return rowView;
	}

	public static class ViewOption {
		private String _contentOption;
		private int _idOption;
		private int _typeOption;
		private int _result;// 1 tra loi sai, 2 tra loi dung, 3 khong tra loi(the hien la dung)

		public ViewOption() {
			this._contentOption = "";
			this._idOption = 0;
			this._typeOption = -1;
			this._result = 0;
		}

		public ViewOption(int id, int type, int result, String cont) {
			this._contentOption = cont;
			this._idOption = id;
			this._typeOption = type;
			this._result = result;
		}

		public void set_contentOption(String _contentOption) {
			this._contentOption = _contentOption;
		}

		public String get_contentOption() {
			return _contentOption;
		}

		public void set_idOption(int _idOption) {
			this._idOption = _idOption;
		}

		public int get_idOption() {
			return _idOption;
		}

		public void set_typeOption(int _typeOption) {
			this._typeOption = _typeOption;
		}

		public int get_typeOption() {
			return _typeOption;
		}

		public void set_result(int _result) {
			this._result = _result;
		}

		public int get_result() {
			return _result;
		}
	}

}
